<template>
    <div class="e-form">
        <div class="tabs">
            <div class="tabs-title">基本信息</div>
            <div style="width: 100%" class="form">
                <el-form :model="formData" label-width="170px" :rules="rules" ref="ruleForm">
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="招标编号" width="220">
                                <div style="display: flex">
                                    <el-input v-model="formData.tenderApplyNo" disabled></el-input>
                                    <ComShowBiddingButton :tenderId="tenderId" mod="equipment" />
                                </div>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="拟招标项目名称" width="200">
                                <span>{{ formData.tenderName }}</span>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="拟招标金额（元）">
                                <span>{{ formData.tenderAmount }}</span>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="招标方式">
                                <span>{{ formData.tenderForm | tenderForm(this) }}</span>
                                <!-- <el-select v-model="formData.tenderForm" placeholder="请选择" @change="selectChange($event, '招标方式')">
                                    <el-option v-for="(item, index) in options.tenderForm" :key="index" :label="item.kvKey" :value="item.kvId">
                                    </el-option>
                                </el-select> -->
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="关闭时间">
                                <span>{{ formData.closeDate }}</span>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-form-item label="招标项目工程概况：" prop="projectOverview">
                            <el-input
                                type="textarea"
                                :rows="2"
                                v-model="formData.projectOverview"
                                disabled
                            >
                            </el-input>
                        </el-form-item>
                    </el-row>
                    <el-row>
                        <el-form-item label="关闭原因：" prop="closeReason">
                            <el-input type="textarea" :rows="2" v-model="formData.closeReason">
                            </el-input>
                        </el-form-item>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="录入机构">
                                <span>{{ formData.orgName }}</span>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24" style="margin-top: 10px">
                            <el-form-item label="状态">
                                <span>草稿</span>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
        </div>
        <div class="buttons">
            <!-- <span class="tip"
                    ><span style="color: red; margin-right: 0">*</span
                    >为必填项</span
                > -->
            <!-- <el-button
                    type="primary"

                    class="btn-blue"
                    >打印</el-button
                >
                <el-button
                    type="primary"

                    class="btn-blue"
                    >删除</el-button
                >
                <el-button
                    type="primary"

                    class="btn-blue"
                    >发布</el-button
                >
                <el-button
                    type="primary"

                    class="btn-blue"
                    >审核</el-button
                >
                <el-button
                    type="primary"

                    class="btn-blue"
                    >撤回</el-button
                > -->
            <el-button type="primary" class="btn-blue" @click="submit">保存</el-button>
            <el-button @click="handleClose">取消</el-button>
        </div>
    </div>
</template>

<script>
// import ComTreeTable from '@/templates/table/treeTable.vue'
// import ComTreeFile from '@/templates/table/treeFile.vue'
// import ComPagination from '@/components/pagination/pagination.vue'
// import applyCloseRequest from '@/api/tender/applyClose.js'
// import applyRequest from '@/api/tender/apply.js'
import equipmentLeasingRequest from '@/api/tender/equipmentLeasing.js'
import ComShowBiddingButton from '@/pages/bidding/common/showBiddingButton.vue'
import { mapState } from 'vuex'

export default {
    data () {
        return {
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            },
            tableData: [],
            value: '',
            textarea: '',
            formData: {
                billId: '',
                billNo: '',
                closeDate: '',
                closeReason: '',
                founderId: '',
                founderName: '',
                gmtCreate: '',
                gmtModified: '',
                nullifyCreated: '',
                nullifyCreator: '',
                nullifyCreatorId: '',
                nullifyDescription: '',
                nullifyReason: '',
                orgId: '',
                orgName: '',
                projectOverview: '',
                state: 0,
                tenderAmount: 0,
                tenderApplyId: '',
                tenderApplyNo: '',
                tenderForm: '',
                tenderName: '',
                workId: ''
            },
            test: '',
            selectData: [],
            selectTableColumnAttr: [
                {
                    label: '单据编号',
                    prop: 'billNo'
                },
                {
                    label: '拟招标项目名称',
                    prop: 'tenderName'
                },
                {
                    label: '单据日期',
                    prop: 'gmtCreate'
                },
                {
                    label: '单据机构名称',
                    prop: 'orgName'
                }
            ],
            selectTableColumnWidth: {
                leftWidth: '150',
                rightWidth: '100'
            },
            selectDataPagination: {},
            front: {
                closeOrgName: '',
                tenderClass: ''
            },
            rules: {
                // projectOverview: {
                //     required: true,
                //     message: '请输入招标需求陈述',
                //     trigger: 'blur'
                // },
                closeReason: [{
                    required: true,
                    message: '请输入关闭原因：',
                    trigger: 'blur'
                },
                { min: 1, max: 500, message: '长度在 1 到 500 个字符', trigger: 'blur' }]
            }
        }
    },
    computed: {
        ...mapState({
            options: state => state.biddingApplication.dictionaries
        }),
        tenderId () {
            return this.$route.query.tenderId || this.$route.query.billid
        }
    },
    components: {
        // ComTreeTable,
        // ComTreeFile,
        // ComPagination,
        ComShowBiddingButton
    },
    created () {
        this.init()
    },
    mounted () {},
    beforeDestroy () {
        this.$notify.closeAll()
    },
    methods: {
        getNowDate () {
            // 个位数前补0
            const zeroFill = function (num) {
                if (parseInt(num) < 10) {
                    num = '0' + num
                }
                return num
            }
            let nowtime = new Date()
            nowtime =
                zeroFill(nowtime.getFullYear()) +
                '-' +
                zeroFill(nowtime.getMonth() + 1) +
                '-' +
                zeroFill(nowtime.getDate())
            return nowtime
            // this.$set(this.formData, 'gmtCreate', nowtime)
        },
        selectChange (kvId, label) {
            if (label === '招标方式') {
                this.options.tenderForm.forEach(item => {
                    if (kvId === item.value) {
                        this.formData.tenderFormName = item.label
                    }
                })
            } else if (label === '币种') {
                this.options.currency.forEach(item => {
                    if (item.kvValue === kvId) {
                        this.formData.currency = item.kvKey
                    }
                })
            }
        },
        async init () {
            await equipmentLeasingRequest.applyGetById({ id: this.tenderId }).then(res => {
                // 招标申请id
                this.formData.tenderApplyId = res.billId
                // 招标申请编号
                this.formData.tenderApplyNo = res.billNo
                // 	拟招标项目名称
                this.formData.tenderName = res.tenderName
                // 	招标方式
                this.formData.tenderForm = res.tenderForm
                // 招标类型
                // this.front.tenderClass = res.tenderClass
                //  关闭日期
                this.formData.closeDate = this.getNowDate()
                // 	招标机构
                this.formData.orgId = this.$store.state.userInfo.orgInfo.orgName
                this.formData.orgName = this.$store.state.userInfo.orgInfo.orgName
                // 工程概况
                this.formData.projectOverview = res.purchaseDemandStatement
                // 招标金额
                this.formData.tenderAmount = res.tenderAmount
                // 申请机构
                // this.org.applyOrgName = res.applyOrgName
                // 录入机构
                // this.front.orgName = res.orgName
                // 关闭机构
                // this.front.closeOrgName = this.$store.state.userInfo.orgInfo.orgName
                delete this.formData.workId
            })
            // await equipmentLeasingRequest.tenderApplyFindById(this.tenderId).then(res => {
            //     // 表单提交信息映射基础招标信息
            //     const tenderData = res
            //     Object.keys(this.formData).forEach(formDataKey => {
            //         Object.keys(tenderData).forEach(tenderDataKey => {
            //             if (formDataKey === tenderDataKey) {
            //                 console.log(this.formData[formDataKey])
            //                 this.formData[formDataKey] = tenderData[tenderDataKey]
            //             }
            //         })
            //     })
            //     // 部分数据对应不上，需要增改
            //     this.formData.tenderApplyId = tenderData.billId // res的billid是招标id，新增补遗招标id是tenderApplyId
            //     this.formData.tenderApplyNo = tenderData.billNo
            //     delete this.formData.billId // 新增不需要表单的billId
            //     delete this.formData.billNo
            //     this.formData.closeOrgId = tenderData.orgId
            //     this.formData.closeOrgName = tenderData.orgName
            // })
        },
        showBidding () {
            if (!this.tenderId) return // 前期需求可切换，现在不需要
            this.$notify.closeAll()
            this.$notify({
                title: '查看招标详情',
                dangerouslyUseHTMLString: true,
                message: `正式环境：客户端打开新页面<br>
                测试环境：手动打开新页面<br>
                <textarea cols="35" rows="10">http://localhost:8080/biddingApplicationShow?tenderId=${this.tenderId}</textarea>
                `,
                duration: 0
            })
            // this.$router.push({
            //     path: './biddingApplicationShow',
            //     query: { tenderId: this.tenderId }
            // })
        },
        noInputFocus () {
            this.$refs.noInput.blur()
        },
        submit () {
            this.$refs.ruleForm.validate(valid => {
                if (valid) {
                    equipmentLeasingRequest.closeCreate(this.formData).then(res => {
                        const callBack = () => {
                            this.$router.push({
                                path: './equipHireBidClosingEdit',
                                query: { billid: res }
                            })
                        }
                        const cancelCallBack = () => {
                            this.$router.push({
                                path: './equipHireBiddingApplicationEdit',
                                query: { billid: this.tenderId, seat: 'close' }
                            })
                        }
                        this.clientPop(
                            'suc',
                            '保存成功，是否继续？',
                            callBack,
                            null,
                            cancelCallBack
                        )
                    })
                } else {
                    return false
                }
            })
        },
        handleClose () {
            this.$router.push({
                path: './equipHireBiddingApplicationEdit',
                query: { billid: this.tenderId, seat: 'close' }
            })
        }
    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.e-form {
    padding: 0 20px;
    /* .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    } */
}
.form {
    margin-top: 10px;
}

.e-table {
    background: #fff;

    /* .top {
    .left {
      padding: 20px;
      padding-top: 0px;
    }
  } */
}

.upload {
    margin: 20px auto;
    display: flex;
    justify-content: center;
    text-align: center;
}

.upload-demo {
    display: flex;
    justify-content: center;
    align-items: center;
}
.el-tab-pane {
    margin-left: -10px;
}
</style>
